<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>合作伙伴监控</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>合作伙伴名称：</th>
                    <td style="width:120px">
                        <input name="name" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>状态：</th>
                    <td style="width:120px">
                        <select id="statusSelect" name="status" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="0">全部</option>
                            <option value="1">启用</option>
                            <option value="2">禁用</option>
                        </select>
                    </td>
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"> </table>



<div id="showS" class="easyui-window" title="电站详情" data-options="closed:true,iconCls:'icon-save'" style="width:1500px;height:500px;padding:10px;">
    <table id="dgs" height="100%"> </table>
</div>

<div id="showC" class="easyui-window" title="中控详情" data-options="closed:true,iconCls:'icon-save'" style="width:1500px;height:500px;padding:10px;">
    <table id="dgc" height="100%"> </table>
</div>

<div id="showT" class="easyui-window" title="终端详情" data-options="closed:true,iconCls:'icon-save'" style="width:1500px;height:500px;padding:10px;">
    <table id="dgt" height="100%"> </table>
</div>

<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        dg.datagrid({
            url:'/v1/api0/partnerInfo/list',
            columns:[[
                {field:'id',title:'ID',width:60,hidden:"true"},
                {field:'name',title:'名称',width:100},
                {field:'leaderName',title:'责任人',width:100},
                {field:'mobile',title:'电话',width:100},
                {field:'remarks',title:'备注',width:100},
                {field:'stationNum',title:'电站数',width:100},
                {field:'consoleNum',title:'中控箱数',width:100},
                {field:'terminalNum',title:'充电终端数',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'action',title:'操作',width:120,formatter: function(value,row,index){
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showStation(\''+row.id+'\')">电站信息</a> | ' +
                                '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showConsole(\''+row.id+'\')">中控信息</a> | ' +
                                '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showTerminal(\''+row.id+'\')">终端信息</a>';
                }}
            ]],
            title:'合作伙伴监控',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false,
            toolbar: [{
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }]
        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/partnerInfo/list',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        onSearch();
    }
    function submitForm(){
        var id = $("#ff input[name='id']").val();
        var url = id.length ? "/v1/api0/user/edit" : "/v1/api0/user/add";
        var data = $('#ff').serialize();
        if(data == $('body').data('ff-serialize')) {
            top.window.showMessage("数据没有改动");
            return;
        }
        $.ajax({
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                if (!$('#ff').form('validate')){
                    return false;
                }
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        });
    }

    function closeWindow(){
        $('#showS').window('close');
        $('#showC').window('close');
        $('#showT').window('close');
    }

    function showStation(id) {
        var dgs = $('#dgs').datagrid();
        dgs.datagrid({
            url:'/v1/api0/partnerInfo/showStation',
            queryParams:{partnerId:id},
            columns:[[
                {field:'id',title:'ID',width:60,hidden:"true"},
                {field:'name',title:'名称',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'createTime',title:'创建时间',width:100,formatter: formatDateTime},
                {field:'createrId',title:'创建人id',width:100,hidden:"true"},
                {field:'creater',title:'创建人',width:100},
                {field:'managerName',title:'代理商',width:100},
                {field:'partenerName',title:'合作伙伴',width:100},
                {field:'address',title:'地址',width:100},
                {field:'stationType',title:'电站类型',width:100}
                ]],
                pagination: true
                });
        $('#showS').window('open');
    }

    function showConsole(id) {
        var dgc = $('#dgc').datagrid();
        dgc.datagrid({
            url:'/v1/api0/partnerInfo/showConsole',
            queryParams:{partnerId:id},
            columns:[[
                 {field:'id',title:'ID',width:60,hidden:"true"},
                {field:'machineCode',title:'机器码',width:100},
                {field:'businessCode',title:'业务码',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'createTime',title:'创建时间',width:100,formatter: formatDateTime},
                {field:'creater',title:'创建人',width:100},
                {field:'stationId',title:'电站id',width:100,hidden:"true"},
                <!--{field:'terminalNumber',title:'终端数量',width:100},-->
                <!--{field:'qrode',title:'二维码',width:100}-->
                ]],
                pagination: true
                });
        $('#showC').window('open');
    }

    function showTerminal(id) {
        var dgt = $('#dgt').datagrid();
        dgt.datagrid({
            url:'/v1/api0/partnerInfo/showTerminal',
            queryParams:{partnerId:id},
            columns:[[
                 {field:'id',title:'ID',width:60,hidden:"true"},
                {field:'machineCode',title:'机器码',width:100},
                {field:'businessCode',title:'业务码',width:100},
                {field:'status',title:'状态',width:60,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                {field:'createime',title:'创建时间',width:100,formatter: formatDateTime},
                {field:'creater',title:'创建人',width:100},
                {field:'consoleId',title:'中控id',width:100,hidden:"true"},
                <!--{field:'qrCode',title:'二维码',width:100}-->
                ]],
                pagination: true
                });
        $('#showT').window('open');
    }

    function ajaxOption(url, data) {
        return {
            type: "post",
            url: url,
            data: data,
            datatype: "json",
            beforeSend: function () {
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if(data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        }
    }
</script>
</body>
</html>
